package com.hsjk.szwj.module.train.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hsjk.szwj.framework.tenant.core.aop.TenantIgnore;
import com.hsjk.szwj.module.train.api.dto.ProductSkuBindDTO;
import com.hsjk.szwj.module.train.api.dto.ProductSkuDTO;
import com.hsjk.szwj.module.train.convert.ProductConvert;
import com.hsjk.szwj.module.train.dal.dataobject.product.ProductSkuBindDO;
import com.hsjk.szwj.module.train.dal.dataobject.product.ProductSkuDO;
import com.hsjk.szwj.module.train.dal.mysql.product.IProductSkuBindMapper;
import com.hsjk.szwj.module.train.dal.mysql.product.IProductSkuMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author chenjiawei
 * @desc
 * @Date 2023/09/04 22:38
 **/
@Service
public class ProductApiImpl implements IProductApi {
    @Resource
    private IProductSkuBindMapper productSkuBindMapper;
    @Resource
    private IProductSkuMapper productSkuMapper;

    @Override
    @TenantIgnore
    public List<ProductSkuBindDTO> getProductSkuBindListBySkuId(Long skuId) {
        List<ProductSkuBindDO> productSkuBindDOS = productSkuBindMapper.selectList(new LambdaQueryWrapper<ProductSkuBindDO>()
                .eq(ProductSkuBindDO::getSkuId, skuId));
        return ProductConvert.INSTANCE.convertProductSkuBindList(productSkuBindDOS);
    }

    @Override
    @TenantIgnore
    public ProductSkuDTO getProductSkuInfoById(Long id) {
        ProductSkuDO productSkuDO = productSkuMapper.selectById(id);
        return ProductConvert.INSTANCE.convertProductSkuDTO(productSkuDO);
    }
}
